<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
        <!--工具栏-->
        <div class="head-container">
          <div v-if="crud.props.searchToggle">
            <!-- 搜索 -->
            <el-input
              v-model="query.blurry"
              clearable
              size="small"
              placeholder="输入字典类型"
              style="width: 200px;"
              class="filter-item"
              @keyup.enter.native="crud.toQuery"
            />
            <rrOperation />
          </div>
          <crudOperation show="" :permission="permission" />
        </div>
        <!--表单渲染-->
        <el-dialog append-to-body :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="700px">
          <el-form ref="form" :inline="true" :model="form" :rules="rules" size="small" label-width="96px">
            <el-form-item label="字典属性名称：" prop="dictName">
              <el-input v-model="form.dictName" />
            </el-form-item>
            <el-form-item label="字典值：" prop="dictCode">
              <el-input v-model="form.dictCode" />
            </el-form-item>
            <el-form-item label="序号：" prop="sort">
              <el-input v-model.number="form.sort" />
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button type="text" @click="crud.cancelCU">取消</el-button>
            <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
          </div>
        </el-dialog>
        <el-table ref="table" v-loading="crud.loading" :data="crud.data" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
          <el-table-column type="selection" width="55" />
          <el-table-column :show-overflow-tooltip="true" prop="dict_name" label="字典值名称" />
          <el-table-column :show-overflow-tooltip="true" prop="dict_code" label="字典值" />
          <el-table-column :show-overflow-tooltip="true" prop="sort" label="序号" />
          <el-table-column
            v-permission="['admin','dict:edit','dict:del']"
            label="操作"
            width="150"
            align="center"
            fixed="right"
          >
            <template slot-scope="scope">
              <udOperation
                :data="scope.row"
                :permission="permission"
              />
            </template>
          </el-table-column>
        </el-table>
      </el-col>
    </el-row>
  </div>
</template>
<style scoped lang="scss">

</style>
<script>

import CRUD, { crud, form, header, presenter } from '@crud/crud'
import crudOperation from '@crud/CRUD.operation.vue'
import rrOperation from '@crud/RR.operation.vue'
import udOperation from '@crud/UD.operation.vue'
import dictValue from '@/api/system/dict_value'
const defaultForm = { dictTypeId: null, dictName: null, dictCode: null, sort: null }
export default {
  name: 'DictValue',
  components: { crudOperation, rrOperation, udOperation },
  props: ['id'],
  cruds() {
    defaultForm.dictTypeId = this.propsData.id
    return CRUD({ title: '字典子类型', url: 'api/dict_value', crudMethod: { ...dictValue }, query: { enabled: 'true', typeId: defaultForm.dictTypeId }})
  },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  data() {
    return {
      permission: {
        add: ['admin', 'dict:add'],
        edit: ['admin', 'dict:edit'],
        del: ['admin', 'dict:del']
      },
      rules: {
        dictName: [
          { required: true, message: '请输入字典名称', trigger: 'blur' },
          { min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur' }
        ],
        dictCode: [
          { required: true, message: '请输入字典值', trigger: 'blur' },
          { min: 2, max: 3, message: '长度在 2 到 3 个数字字符', trigger: 'blur' }
        ],
        sort: [
          { required: true, message: '请输入序号', trigger: 'blur' },
          { type: 'number', message: '序号必须为数字值' }
        ]
      }
    }
  },
  mounted() {
  },
  methods: {

  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
::v-deep .vue-treeselect__control,::v-deep .vue-treeselect__placeholder,::v-deep .vue-treeselect__single-value {
  height: 30px;
  line-height: 30px;
}
</style>
